package cn.wolfcode.p2p.bussness.service.impl;

import cn.wolfcode.p2p.base.util.UserContext;
import cn.wolfcode.p2p.bussness.domain.BidRequest;
import cn.wolfcode.p2p.bussness.domain.BidRequestAuditHistory;
import cn.wolfcode.p2p.bussness.mapper.BidRequestAuditHistoryMapper;
import cn.wolfcode.p2p.bussness.service.IBidRequestAuditHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class BidrequestAuditHistoryServiceImpl implements IBidRequestAuditHistoryService {

    @Autowired
    private BidRequestAuditHistoryMapper bidrequestAuditHistoryMapper;

    @Override
    public void createHistory(BidRequest br, String remark, Integer state) {
        BidRequestAuditHistory history = new BidRequestAuditHistory();
        history.setAuditType(BidRequestAuditHistory.TYPE_PUBLISH);
        history.setBidRequestId(br.getId());
        history.setApplier(br.getCreateUser());
        history.setApplyTime(br.getApplyTime());
        history.setAuditor(UserContext.getCount());
        history.setRemark(remark);
        history.setAuditTime(new Date());
        history.setState(state);
        history.setApplyTime(new Date());
        bidrequestAuditHistoryMapper.insert(history) ;
    }

    @Override
    public List<BidRequestAuditHistory> queryListByBidRequestId(Long bidRequestId) {
        return bidrequestAuditHistoryMapper.queryListByBidRequestId(bidRequestId);
    }

    @Override
    public void save(BidRequestAuditHistory h) {
        this.bidrequestAuditHistoryMapper.insert(h);
    }
}
